/**
 * @author SaoE
 * @date 2025/2/23 17:28
 */
public class arrayToBTree {
    public static TreeNode arrayToBTree(int[] arr) {
        if (arr == null || arr.length == 0) {
            return null;
        }
        TreeNode root = new TreeNode(arr[0]);
        for (int i = 1; i < arr.length; i++) {
            TreeNode node = root;
            while (true) {
                if (arr[i] < node.val) {
                    if (node.left == null) {
                        node.left = new TreeNode(arr[i]);
                        break;
                    } else {
                        node = node.left;
                    }
                } else {
                    if (node.right == null) {
                        node.right = new TreeNode(arr[i]);
                    }
                }
            }
        }
        return root;

    }
}
